﻿namespace EyeOpen.Cart.Service
{
    using System;
    using System.Collections.Generic;
    using EyeOpen.Cart.Linq;

    public class ArticleLineService
    {
        public IList<ArticleLineDto> GetAll()
        {
            IList<ArticleLineDto> data =
                new List<ArticleLineDto>
                {
                    new ArticleLineDto
                    {
                        Id = new Guid("357cc8da-4d68-42d6-90e8-6750c25b40a3"),
                        ProductName = "Apple",
                        Price = 10f,
                        Quantity = 1,
                        Iva = 20f,
                    },
                    new ArticleLineDto
                    {
                        Id = new Guid("4061d797-0964-442b-a903-5cd23379b414"),
                        ProductName = "Orange",
                        Price = 7.3f,
                        Quantity = 1,
                        Iva = 20f
                    },
                    new ArticleLineDto
                    {
                        Id = new Guid("b133b5e8-f4c5-4ff5-a2b0-d890529e35eb"),
                        ProductName = "Banana",
                        Price = 3.4f,
                        Quantity = 1,
                        Iva = 20f
                    }
                };

            data.ForEach(articleLineDto => articleLineDto.Total = this.CalculateArticleLineTotal(articleLineDto));

            return data;
        }

        public float CalculateArticleLineTotal(ArticleLineDto articleLineDto)
        {
            return (articleLineDto.Price * articleLineDto.Quantity) * (1 + (articleLineDto.Iva / 100)); 
        }

        public float CalculateArticlesTotal(IEnumerable<ArticleLineDto> collection) 
        {
            float total = 0;

            foreach (ArticleLineDto item in collection)
            {
                total += item.Total;
            }

            return total;
        }
    }
}